package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.common.ConsoleConstant;
import com.fdb.efp.nls.service.dao.LmtUnfreezeAppDao;
import com.fdb.efp.nls.service.domain.LmtUnfreezeApp;
import com.fdb.efp.nls.service.facade.LmtUnfreezeAppService;
import com.fdb.efp.nls.service.vo.LmtUnfreezeAppVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>ServiceImpl: 额度解冻申请表				<p>
 * @author ligm
 * @date 2019-08-10
 */
@Service("lmtUnfreezeAppService")
public class LmtUnfreezeAppServiceImpl implements LmtUnfreezeAppService, FrameworkService {

	private static Logger logger = LoggerFactory.getLogger(LmtUnfreezeAppServiceImpl.class);

	@Autowired
	private LmtUnfreezeAppDao lmtUnfreezeAppDao;

	/**
	 * 新增操作
	 */
	public int insertLmtUnfreezeApp(LmtUnfreezeAppVO inLmtUnfreezeAppVo) {
		logger.debug("当前新增数据为:"+ inLmtUnfreezeAppVo.toString());
		int num = 0;
		try {
			LmtUnfreezeApp lmtUnfreezeApp = new LmtUnfreezeApp();
			beanCopy(inLmtUnfreezeAppVo, lmtUnfreezeApp);
			num = lmtUnfreezeAppDao.insertLmtUnfreezeApp(lmtUnfreezeApp);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(LmtUnfreezeAppVO inLmtUnfreezeAppVo) {
		logger.debug("当前删除数据条件为:"+ inLmtUnfreezeAppVo);
		int num = 0;
		try {
			LmtUnfreezeApp lmtUnfreezeApp = new LmtUnfreezeApp();
			beanCopy(inLmtUnfreezeAppVo, lmtUnfreezeApp);
			num = lmtUnfreezeAppDao.deleteByPk(lmtUnfreezeApp);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inLmtUnfreezeAppVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(LmtUnfreezeAppVO inLmtUnfreezeAppVo) {
		logger.debug("当前修改数据为:"+ inLmtUnfreezeAppVo.toString());
		int num = 0;
		try {
			LmtUnfreezeApp lmtUnfreezeApp = new LmtUnfreezeApp();
			beanCopy(inLmtUnfreezeAppVo, lmtUnfreezeApp);
			num = lmtUnfreezeAppDao.updateByPk(lmtUnfreezeApp);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inLmtUnfreezeAppVo +"修改的数据条数为"+ num);
		return num;
	}

	/**
	 * 查询操作
	 */
	public LmtUnfreezeAppVO queryByPk(LmtUnfreezeAppVO inLmtUnfreezeAppVo) {

		logger.debug("当前查询参数信息为:"+ inLmtUnfreezeAppVo);
		try {
			LmtUnfreezeApp queryLmtUnfreezeApp = new LmtUnfreezeApp();
			beanCopy(inLmtUnfreezeAppVo, queryLmtUnfreezeApp);
			LmtUnfreezeApp queryRslLmtUnfreezeApp = lmtUnfreezeAppDao.queryByPk(queryLmtUnfreezeApp);
			if (Objects.nonNull(queryRslLmtUnfreezeApp)) {
				LmtUnfreezeAppVO outLmtUnfreezeAppVo = beanCopy(queryRslLmtUnfreezeApp, new LmtUnfreezeAppVO());
				logger.debug("当前查询结果为:"+ outLmtUnfreezeAppVo.toString());
				return outLmtUnfreezeAppVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<LmtUnfreezeAppVO> queryAllOwner(LmtUnfreezeAppVO lmtUnfreezeAppVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<LmtUnfreezeAppVO> list = null;
		try {
			List<LmtUnfreezeApp> lmtUnfreezeApps = lmtUnfreezeAppDao.queryAllOwnerByPage(lmtUnfreezeAppVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ lmtUnfreezeApps.size());
			pageSet(lmtUnfreezeApps, lmtUnfreezeAppVo);
			list = (List<LmtUnfreezeAppVO>) beansCopy(lmtUnfreezeApps, LmtUnfreezeAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<LmtUnfreezeAppVO> queryAllCurrOrg(LmtUnfreezeAppVO lmtUnfreezeAppVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<LmtUnfreezeApp> lmtUnfreezeApps = lmtUnfreezeAppDao.queryAllCurrOrgByPage(lmtUnfreezeAppVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+lmtUnfreezeApps.size());
		List<LmtUnfreezeAppVO> list = null;
		try {
			pageSet(lmtUnfreezeApps, lmtUnfreezeAppVo);
			list = (List<LmtUnfreezeAppVO>) beansCopy(lmtUnfreezeApps, LmtUnfreezeAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<LmtUnfreezeAppVO> queryAllCurrDownOrg(LmtUnfreezeAppVO lmtUnfreezeAppVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<LmtUnfreezeApp> lmtUnfreezeApps = lmtUnfreezeAppDao.queryAllCurrDownOrgByPage(lmtUnfreezeAppVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ lmtUnfreezeApps.size());
		List<LmtUnfreezeAppVO> list = null;
		try {
			pageSet(lmtUnfreezeApps, lmtUnfreezeAppVo);
			list = (List<LmtUnfreezeAppVO>) beansCopy(lmtUnfreezeApps, LmtUnfreezeAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;

	}
	/**
	 * 查询审批中的额度解冻申请
	 */
	@Override
	public List<LmtUnfreezeAppVO> queryLmtContNoByPk(LmtUnfreezeAppVO lmtTerminateAppVO) {
		logger.debug("当前查询授信协议审批中的参数信息为:" + lmtTerminateAppVO.getLmtContNo());
		List<LmtUnfreezeAppVO> list = null;
		LmtUnfreezeAppVO lmtUnfreezeAppVO = new LmtUnfreezeAppVO();
		lmtUnfreezeAppVO.setLmtContNo(lmtTerminateAppVO.getLmtContNo());
		lmtUnfreezeAppVO.setApproveStatus(ConsoleConstant.APRV_STATUS_02);
		try {
			List<LmtUnfreezeApp> lmtUnfreezeApps = lmtUnfreezeAppDao.queryLmtContNoByPk(lmtUnfreezeAppVO);
			logger.debug("当前查询授信协议审批中的结果集数量为:"+ lmtUnfreezeApps.size());
			pageSet(lmtUnfreezeApps, lmtUnfreezeAppVO);
			list = (List<LmtUnfreezeAppVO>) beansCopy(lmtUnfreezeApps, LmtUnfreezeAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		return list;
	}
	/**
	 * 查询当前授信协议的全部数据
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<LmtUnfreezeAppVO> queryByLmtContNoAll(LmtUnfreezeAppVO inLmtUnfreezeAppVo) {
		logger.debug("当前查询参数信息为:"+inLmtUnfreezeAppVo);
		List<LmtUnfreezeAppVO> list = null;
		try {
			LmtUnfreezeApp lmtUnfreezeApp=new LmtUnfreezeApp();
			beanCopy(inLmtUnfreezeAppVo, lmtUnfreezeApp);
			List<LmtUnfreezeApp> lmtUnfreezeApps = lmtUnfreezeAppDao.queryByLmtContNoAll(inLmtUnfreezeAppVo);
			logger.debug("当前查询授信协议未处理完成的结果集数量为:"+ lmtUnfreezeApps.size());
			pageSet(lmtUnfreezeApps, inLmtUnfreezeAppVo);
			list = (List<LmtUnfreezeAppVO>) beansCopy(lmtUnfreezeApps, LmtUnfreezeAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;
	}

	@Override
	public List<LmtUnfreezeAppVO> queryAllByCoditions(LmtUnfreezeAppVO lmtUnfreezeAppVO) {
		logger.debug("当前查询参数信息为:"+lmtUnfreezeAppVO);
		List<LmtUnfreezeAppVO> list = null;
		try {
			LmtUnfreezeApp lmtUnfreezeApp=new LmtUnfreezeApp();
			beanCopy(lmtUnfreezeAppVO, lmtUnfreezeApp);
			List<LmtUnfreezeApp> lmtUnfreezeApps = lmtUnfreezeAppDao.queryAllByCoditionsByPage(lmtUnfreezeAppVO);
			logger.debug("当前查询的结果集数量为:"+ lmtUnfreezeApps.size());
			pageSet(lmtUnfreezeApps, lmtUnfreezeAppVO);
			list = (List<LmtUnfreezeAppVO>) beansCopy(lmtUnfreezeApps, LmtUnfreezeAppVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}

		return list;
	}
}
